package com.caijin.web.controller.system.task;


import com.caijin.common.core.domain.Result;
import com.caijin.common.core.domain.entity.TaskInfo;
import com.caijin.system.service.ITaskInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;

/**
 * <p>
 * 作业信息表 前端控制器
 * </p>
 *
 * @author Peas
 * @since 2021-05-28
 */
@RestController
@RequestMapping("/system/taskInfo")
public class TaskInfoController {

    @Autowired
    private ITaskInfoService taskInfoService;

    /**
     * 发布作业接口
     */
    @ApiOperation("发布作业接口")
    @RequestMapping(method = RequestMethod.POST,
            path = "/post")
    public Result postTask(@RequestBody TaskInfo taskInfo) {
        return taskInfoService.postTask(taskInfo);

    }

    /**
     * 获取作业列表接口
     */
    @ApiOperation("获取作业列表接口")
    @RequestMapping(method = RequestMethod.GET,
            path = "/getList")
    public Result getTaskList(@RequestParam("cno") Long cno) {
        return taskInfoService.getTaskList(cno);
    }

    /**
     * 获取作业信息接口
     */
    @ApiOperation("获取作业信息接口")
    @RequestMapping(method = RequestMethod.GET,
            path = "/get")
    public Result getTask(@RequestParam("id") Long id) {
        TaskInfo byId = taskInfoService.getById(id);
        Result result = new Result();
        result.data("data", byId).success(true);
        return result;
    }

    /**
     * 修改作业信息接口
     */
    @ApiOperation("修改作业信息接口")
    @RequestMapping(method = RequestMethod.POST,
            path = "/update")
    public Result updateTask(@RequestBody TaskInfo taskInfo) {
        return taskInfoService.updateById(taskInfo) ? Result.ok() : Result.error();
    }

    /**
     * 删除作业信息接口
     */
    @ApiOperation("删除作业信息接口")
    @RequestMapping(method = RequestMethod.DELETE,
            path = "/delete")
    public Result deleteTask(@RequestParam("id") Long id) {
        return taskInfoService.getBaseMapper().deleteById(id) == 1 ? Result.ok() : Result.error();
    }
}

